package com.wc.alorithm_blue_bridge._动态规划.Q3741;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/15 12:34
 * @description 倒水
 * https://www.lanqiao.cn/problems/3741/learning/?page=1&first_category_id=1
 */


public class Main {
    static int maxN = 1007;
    static long[] dp = new long[maxN];
    static FastReader sc = new FastReader();
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        int a, b, c, d, e;
        for (int i = 1; i <= n; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            c = sc.nextInt();
            d = sc.nextInt();
            e = sc.nextInt();
            for (int j = m; j >= 0; j--) {
                dp[j] += e;
                if (j >= a) {
                    dp[j] = Math.max(dp[j], dp[j - a] + b);
                }
                if (j >= c) {
                    dp[j] = Math.max(dp[j], dp[j - c] + d);
                }
            }
        }

        System.out.println(dp[m]);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
